import requests
import json
import datetime


def send_msg(token_dd, date_str, msg, at_all=True):
    url = "https://oapi.dingtalk.com/robot/send?access_token=4cfb5e0a923b5b659c97d171768d68cbad899773289eeef0799166259a4e5cbd"
    content_str = "{0}定时推送：\n\n{1}\n".format(date_str, msg)

    data = {
        "msgtype": "text",
        "text": {
            "content": content_str
        },
        "at": {
            "isAtAll": True
        }
    }

    headers = {"Content-Type": "application/json;charset=utf-8"}

    res = requests.post(url=url, headers=headers, data=json.dumps(data))

    print("钉钉消息发送结果：", res.json())
    return res.text



if __name__ == "__main__":
    token_dd = ""
    note_str = "feapder报警系统店铺异常"
    date_str = datetime.datetime.now().strftime("%H:%M")
    send_msg(token_dd, date_str, note_str, True)
